<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<h1>Tellimused</h1>
<div>
    <c:if test="${not empty statusMessageKey}">
       <div style="color:green; padding:20px;"><fmt:message key="${statusMessageKey}"/></div>
    </c:if>

    <spring:hasBindErrors name="serviceOrder">
        <div id="error" style="display:block !important;" class="rounderCorners20">
            <ul>
            <c:forEach var="error" items="${errors.allErrors}">
                <li>${error.defaultMessage}</li>
            </c:forEach>
            </ul>
        </div>
    </spring:hasBindErrors>
</div>

<c:if test="${serviceOrder.id > -1}">
	<form:form modelAttribute="serviceOrder">
	    <form:hidden path="id" />
		<c:if test="${serviceOrder.id > 0}">
	    		<c:if test="${serviceOrder.id > 0}">
		            <h3>Tellimuse nr: <c:out value="${serviceOrder.id}"/></h3>
	            </c:if>
	    		<h3>Kokku: <c:out value="${serviceOrder.price}"/></h3>
        </c:if>
		<table class="formTable">
			<tr>
				<td>Töö:</td>
				<td><form:input path="serviceAction.description" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Teenus:</td>
				<td><form:input path="serviceAction.serviceTypeId" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Kogus:</td>
				<td><form:input path="serviceAction.amount" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Ühiku hind:</td>
				<td><form:input path="serviceAction.price" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Osa:</td>
				<td><form:input path="servicePart.name" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Kogus:</td>
				<td><form:input path="servicePart.count" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Hind:</td>
				<td><form:input path="servicePart.price" class="rounderCorners10" /></td>
			</tr>
			<tr>
				<td>Seadmed:</td>
				<td>
					<form:select path="serviceDevice.device.id">
						<form:options items="${serviceOrder.serviceDevice.deviceList}" itemValue="id" itemLabel="name" />
					</form:select>
				</td>
			</tr>
	        <tr>
				<td>Tellimuse staatus:</td>
				<td>
					<form:select path="soStatusType.id">
						<form:options items="${serviceOrder.soStatusTypeList}" itemValue="id" itemLabel="name" />
					</form:select>
				</td>
			</tr>
			<tr>
				<td colspan="2">
				<c:if test="${serviceOrder.id == 0}">
					<input type="submit" class="button rounderCorners10" id="save" name="_eventId_save" value="Vormista tellimus" onclick="Spring.remoting.submitForm('save', 'serviceOrder', {fragments:'content'}); return false;"/>
				</c:if>
				<c:if test="${serviceOrder.id > 0}">
					<input type="submit" class="button rounderCorners10" id="save" name="_eventId_save" value="Salvesta tellimus" onclick="Spring.remoting.submitForm('save', 'serviceOrder', {fragments:'content'}); return false;"/>
				</c:if>
				</td>
			</tr>
		</table>
	</form:form>
</c:if>
<c:if test="${serviceOrder.id == -1}">
	<c:if test="${not empty serviceOrder.list}">
	    <table id="todoList">
	        <tr>
	            <th>Tellimuse nr.</th>
	            <th>Tellimuse staatus</th>
	            <th>Summa kokku</th>
	            <th></th>
	        </tr>
	     <c:forEach var="order" items="${serviceOrder.list}">
	         <tr>
	             <td>${order.id}</td>
		    	<td>${order.soStatusType.name}</td>
		    	<td>${order.price}</td>
	             <td>
	                 <a href="${flowExecutionUrl}&_eventId=editOrder&orderId=${order.id}" >Muuda</a>
	             </td>
	         </tr>
	     </c:forEach>
	    </table>
	</c:if>
</c:if>